import React, {useEffect, useRef, useState} from 'react';
import {Cartesian3, Cesium3DTileset, Math as CesiumMath, Cartographic, HeadingPitchRange,HomeButton, Command, HomeButtonViewModel, HeadingPitchRoll, Matrix4} from 'cesium';
import {Viewer, Entity, Primitive, Camera, CameraFlyTo} from "cesium-react";
import {isEmpty} from "../../units/globaling/globaling";
import './Home_style.scss';
export default function Home() {
    const a= {};
    console.log(isEmpty(a));
    const viewRef=useRef(null);
    // const [tileSet]=useState(new Cesium3DTileset({url: 'https://3dtiles.idatatlas.com/3dtiles/hm/tileset.json'}));
    const [homeCameraView, setCameraView]=useState(null);
    useEffect(() => {
        if(viewRef.current){
            viewRef.current.cesiumElement.scene.globe.enableLighting = true; //激活基于太阳位置的光照
            let tileSet=  viewRef.current.cesiumElement.scene.primitives.add(new Cesium3DTileset({url: 'https://3dtiles.idatatlas.com/3dtiles/hm/tileset.json'}))
            // viewRef.current.cesiumElement.zoomTo(tileSet, new HeadingPitchRange(0, -0.5, 100));
            // Create an initial camera view
            // Cartesian3 一个三维笛卡尔坐标——当它被用作相对于地球中心的位置时，使用地球固定框架（ECEF）
            const initialPosition = new Cartesian3.fromDegrees(-73.998114468289017509, 40.674512895646692812, 2631.082799425431);
            //HeadingPitchRoll 在东北向上的框架中关于局部轴的旋转（弧度）。航向是围绕负Z轴的旋转。俯仰是围绕负Y轴的旋转。滚动是关于正X轴的旋转。
            const initialOrientation = new HeadingPitchRoll.fromDegrees(7.1077496389876024807, -31.987223091598949054, 0.025883251314954971306);
            const homeCameraView = {
                destination : initialPosition,
                orientation : {
                    heading : initialOrientation.heading,
                    pitch : initialOrientation.pitch,
                    roll : initialOrientation.roll
                }
            };
            // Add some camera flight animation options
            homeCameraView.duration = 2.0;
            homeCameraView.maximumHeight = 2000;
            homeCameraView.pitchAdjustHeight = 2000;
            let ho=HomeButtonViewModel;
            console.log('Command', Command);
            console.log('HomeButton', HomeButton);
            homeCameraView.endTransform = Matrix4.IDENTITY;
// Override the default home button
//             Command.beforeExecute.addEventListener(function (e) {
//                 console.log('e', e);
//                 e.cancel = true;
//                 viewRef.current.cesiumElement.scene.camera.flyTo(homeCameraView);
//             })
            //viewRef.current.cesiumElement.scene.camera.flyTo(homeCameraView);
            // viewRef.current.cesiumElement.scene.camera.setView(homeCameraView)
        }
    });
    return (
        <Viewer full ref={viewRef} />
    );
}


